﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Metier;
using Poco;
using WebApp.Models;

namespace WebApp.Controllers
{
    [Authorize(Roles="Serveur")]
    public class ServeurController : Controller
    {
        //
        // GET: /Serveur/

        public ServeurController()
            : base()
        {
            ViewBag.Home = "/Serveur/";
        }

        [Authorize]
        public ActionResult Index(string email)
        {

            
            return View();
        }

        [Authorize]
        public ActionResult Tables(string email)
        {
            GestionZone manager_zone = new GestionZone();            
            GestionTable manager_table = new GestionTable();
            Zone serverzone = manager_zone.Chercher(User.Identity.Name);
            List<Table> list_table = manager_table.Lister(serverzone);

            ServerModelView servermodelview = new ServerModelView();
            servermodelview.Tables = list_table;
            

            return View("ListTables", servermodelview);
        }

        [Authorize]
        public ActionResult Notifications(string email)
        {
            List<List<Notification>> list_notif_par_commande = new List<List<Notification>>();
            GestionNotification manager_notif = new GestionNotification();
 

            //Zone serverzone = manager_zone.Chercher(User.Identity.Name);
            GestionCommande manager_commandes = new GestionCommande();
            
            foreach (var commande in manager_commandes.Lister(User.Identity.Name))
            {
                list_notif_par_commande.Add(manager_notif.Lister(commande));
            }
            //TypeNotification.AppelServeur;
            ServerModelView servermodelview = new ServerModelView();
            servermodelview.list_notif_par_commande = list_notif_par_commande;
            servermodelview.Notifications = manager_notif.Lister(User.Identity.Name);
            

            return View("ListNotifs", servermodelview);
        }
        [Authorize]
        public ActionResult ValidNotif(int id)
        {
            GestionNotification mana_notif = new GestionNotification();
            try{
                Notification notif = mana_notif.Chercher(id);
                //notif.Fait.Ma;
                //mana_notif.MarquerCommeFait
            }catch(Exception e){
                FlashHelpers.FlashError(this,"Une erreur est survenue pendant la validatino de la notification")
            }

            return RedirectToAction("Notifications");
        }
    }
}
